import turtle


def calculate_bmr(gender, weight, height, age):
    if gender == '男':
        bmr = (13.7 * weight) + (5.0 * height) - (6.8 * age) + 66
    elif gender == '女':
        bmr = (9.6 * weight) + (1.8 * height) - (4.7 * age) + 655
    else:
        bmr = -1
    return bmr


def main():
    exit_program = False
    while not exit_program:
        print('============================')
        print('    计算基础代谢率（BMR）    ')
        print('============================')
        print('请输入以下信息，用空格分隔')
        input_str = input('性别 体重（kg） 身高（cm） 年龄：')

        try:
            gender, weight, height, age = input_str.split()
            weight = float(weight)
            height = float(height)
            age = float(age)

            if gender not in ['男', '女']:
                raise ValueError('性别只能输入男或女')
        except ValueError as e:
            print('输入信息不符合规范：', e)
            print('******************************')
            continue
        else:
            bmr = calculate_bmr(gender, weight, height, age)
            if bmr != -1:
                print('性别：{}，体重：{}公斤，身高：{}厘米，年龄：{}岁'.format(gender, weight, height, age))
                print('基础代谢率：{}大卡'.format(bmr))
                print('******************************')
            else:
                print('性别请输入男或女')
                print('******************************')

        user_input = input('是否退出程序（y/n）？')
        if user_input.lower() == 'y':
            exit_program = True
        else:
            exit_program = False


if __name__ == '__main__':
    main()